package com.liuyfly.leetcode.study;

import com.liuyfly.leetcode.util.LeetcodeUtil;

/**
 * @author liuyangfang at 2022-08-29 01:12
 */
public class ZeroMatrix {

    public static void setZeroes(int[][] matrix) {
        int[] rowFlagArray = new int[matrix.length];
        int[] columnFlagArray = new int[matrix[0].length];
        for (int i=0;i<matrix.length;i++){
            for (int j=0;j<matrix[i].length;j++){
                if (matrix[i][j]==0){
                    rowFlagArray[i]=1;
                    columnFlagArray[j]=1;
                }
            }
        }
        for (int i=0;i<matrix.length;i++){
            for (int j=0;j<matrix[i].length;j++){
                if (rowFlagArray[i]>0||columnFlagArray[j]>0){
                    matrix[i][j]=0;
                }
            }
        }
    }
    public static void main(String[] args) {
        int[][] array = {{11,12,13,14},{15,16,17,18},{19,0,21,22},{23,24,25,26}};
        LeetcodeUtil.printTwoDimensionalArray(array);
        setZeroes(array);
        LeetcodeUtil.printTwoDimensionalArray(array);
    }
}
